//
// Created by 17775 on 2024/9/13.
//

#ifndef RAYCI_DYNAMICPROGRESSBAR_H
#define RAYCI_DYNAMICPROGRESSBAR_H

#include <QProgressBar>
#include <QPainter>

class DynamicProgressBar : public QProgressBar {
public:
    DynamicProgressBar(QWidget *parent = nullptr) : QProgressBar(parent) {}

protected:
    void paintEvent(QPaintEvent *event) override {
        QProgressBar::paintEvent(event); // 调用基类的绘制方法

        QPainter painter(this);
        painter.setRenderHint(QPainter::Antialiasing); // 设置抗锯齿

        // 绘制刻度
        for (int i = 0; i <= 100; i += 5) {
            qreal x = (i / 100.0) * width();
            painter.drawLine(x, 0, x, 5); // 绘制竖直线作为刻度
        }

        // 绘制当前进度的红色部分
        qreal progressWidth = (value() / 100.0) * width();
        QRect progressRect(0, 0, progressWidth, height());
        painter.fillRect(progressRect, Qt::red);
    }
};


#endif //RAYCI_DYNAMICPROGRESSBAR_H
